window.onload = function () {
    showToast= function (obj) {
        var altWrapObj = document.createElement("div");
        altWrapObj.className = "altWrap";
        var toastTemp = "<div class='toasterWrap'>" +
            "<div class='altContMsgWrap'>" +
            "<p>"+obj.msg+"</p>"+
            "</div>"+
            "</div>";
        document.querySelector("body").appendChild(altWrapObj);
        console.log(toastTemp);
        altWrapObj.innerHTML = toastTemp;

        altWrapObj.onclick = function(ev){
            document.querySelector("body").removeChild(altWrapObj);
            ev.preventDefault();
        }
        var tosterTimer = setTimeout(function () {
            document.querySelector("body").removeChild(altWrapObj);
            clearTimeout(tosterTimer);
        },obj.timeout ? obj.timeout : 3000)
    }


    showAlert = function (obj) {
        var obj = obj || {};
        var altWrapObj = document.createElement("div");
        altWrapObj.className = "altWrap";
        document.querySelector("body").appendChild(altWrapObj);

        var confirmTemp = "<div class='altShade'></div>" +
            "<div class='altContMain'>" +
            "<h3 class='alertTitle'>"+obj.title+"</h3>"+
            "<div class='altContMsgWrap'>" +
            "<p class='alertContText'>"+obj.msg+"</p>"+
            "</div>"+
            "<div class='alertBtnWrap'>" +
            "<button class='alertCancelBtn'>取消</button>"+
            "<button class='alertConfirmBtn'>确认</button>"+
            "</div>"+
            "<div>";
        var promptTemp = "<div class='altShade'></div>" +
            "<div class='altContMain'>" +
            "<h3 class='alertTitle'>"+obj.title+"</h3>"+
            "<div class='altContMsgWrap'>" +
            "<p class='alertContText'>请输入打赏钻石数量！</p>"+
            "<input type='number' class='promptInput' ng-model='promptInput'  placeholder='请输入要打赏的钻石数量' value='"+obj.defaultValue+"'>"+
            "</div>"+
            "<div class='alertBtnWrap'>" +
            "<button class='alertCancelBtn'>取消</button>"+
            "<button class='alertConfirmBtn'>确认</button>"+
            "</div>"+
            "<div>";

        if(obj.type === "prompt"){
            altWrapObj.innerHTML = promptTemp;
        }else if(obj.type === "confirm"){
            altWrapObj.innerHTML = confirmTemp;
        }else{
            altWrapObj.innerHTML = "";
        }

        document.querySelector('.altShade').onclick = function(ev){
            document.querySelector("body").removeChild(altWrapObj);
            return false;
        }

        document.querySelector('.alertCancelBtn').onclick = function (ev) {
            document.querySelector("body").removeChild(altWrapObj);
            return false;
        }

        document.querySelector('.alertConfirmBtn').onclick = function (ev) {
            obj.confirmFn();
            return false;
        }
    }



    showModel = function (obj) {
        var obj = obj || {};
        var altWrapObj = document.createElement("div");
        var altShadeObj = document.createElement("div");
        var altMainContObj = document.createElement("div");
        var altMainContTitleObj = document.createElement("h3");
        var altMainContBodyObj = document.createElement("div");
        var altBtnWrapObj = document.createElement("div");
        var altCancelBtnObj = document.createElement("button");
        var altConfirmBtnObj = document.createElement("button");
        altWrapObj.className = "altWrap";
        altShadeObj.className = "altShade";
        altMainContObj.className = "altMainContWrap";
        altMainContTitleObj.className = "altMainContTitle";
        altMainContBodyObj.className = "altMainContBody";
        altBtnWrapObj.className = "altBtnWrap"
        altCancelBtnObj.className = "alertCancelBtn";
        altConfirmBtnObj.className = "alertConfirmBtn";
        altCancelBtnObj.innerHTML = "关闭";
        altConfirmBtnObj.innerHTML = "确认";

        altMainContObj.style.width = obj.width;
        altMainContObj.style.height = obj.height;

        altWrapObj.appendChild(altShadeObj);
        altWrapObj.appendChild(altMainContObj);
        altMainContObj.appendChild(altMainContTitleObj);
        altMainContObj.appendChild(altMainContBodyObj);
        altMainContObj.appendChild(altBtnWrapObj);
        altBtnWrapObj.appendChild(altCancelBtnObj);
        altBtnWrapObj.appendChild(altConfirmBtnObj);
        document.querySelector("body").appendChild(altWrapObj);


        altMainContTitleObj.innerHTML = obj.title ? obj.title : "标题";


        var tempHtml = "<div class='altMainCont'>放内容</div>";

        altMainContBodyObj.innerHTML = obj.tempHtml ? obj.tempHtml : tempHtml;





        altShadeObj.onclick = function(ev){
            document.querySelector("body").removeChild(altWrapObj);
            return false;
        }

        altCancelBtnObj.onclick = function (ev) {
            document.querySelector("body").removeChild(altWrapObj);
            return false;
        }
        altConfirmBtnObj.onclick = function (ev) {
            obj.confirmFn();
            document.querySelector("body").removeChild(altWrapObj);
            return false;
        }
    }



}





